home *** CD-ROM | disk | FTP | other *** search
- //Load the config file.
- //The config contains the path to be walked or the path to an individual file.
- //The path to the data file to be updated.
-
- WScript.Echo(new Date()); // echo when the code started.
-
- var start = new Date(); //Used for perf testing
- var sDate=start.getHours() + ":" + start.getMinutes() + ":" + start.getSeconds() + ":" + start.getMilliseconds()
-
- var warningCount = 0;
- var errorCount = 0;
-
- var gScriptPath=WScript.ScriptFullName.substr(0,2);
- //gfs = new ActiveXObject("Scripting.FileSystemObject");
- var oArgs = WScript.Arguments;
- var gsConfigPath = oArgs(0); //Config file
- var goIterator=new IteratorClass(gsConfigPath);
- goIterator.walk(goIterator.rootPath);
- //WScript.Echo(goIterator.fileCount);
- goIterator.done();
-
- WScript.Echo("The number of errors are " + errorCount + ".");
- WScript.Echo("The number of warnings are " + warningCount + ".");
- WScript.Echo(new Date()); // echo when the code finished.
-
- //Constructor for iterator object
- function IteratorClass(sConfigPath)
- {
- this.fileCount=0;
- this.fs = new ActiveXObject("Scripting.FileSystemObject");
- this.datasets = new Array();
- this.destinations= new Array();
- this.configFile=getConfig(sConfigPath);
- this.getDestination=getDestination;
- this.destinationNodes=this.configFile.selectNodes("/root/datafile")
- for (var i=0;i<this.destinationNodes.length;i++)
- {
- this.destinations[i]=new DestinationClass(this.destinationNodes.item(i))
- }
- this.providerNodes=this.configFile.selectNodes("/root/provider");
- for (var i=0;i<this.providerNodes.length;i++)
- {
- var datasetName=this.providerNodes.item(i).getAttribute("datafilerid");
- this.datasets[i]=new DataSetClass(this.configFile,this.providerNodes.item(i),this.getDestination(datasetName));
- //WScript.Echo(this.datasets[i].name);
- }
- this.rootPath=this.configFile.selectSingleNode("/root/sourcefiles").text;
- this.rootPath=EnsureDriveLetter(this.rootPath);
- this.done=SaveAll;
- this.passAround=passAround;
- this.walk=recursWalk;
- return this;
- }
-
-
- //Constructor for dataset object
- function DataSetClass(oConfigFile,providerNode,destination)
- {
- //var start = new Date(); //Used for perf testing
- //this.startTime=start.getHours() + ":" + start.getMinutes() + ":" + start.getSeconds() + ":" + start.getMilliseconds()
- //this.endTime="";
- this.queryID="";
- this.fixedID="";
- this.datasetName=providerNode.getAttribute("datafilerid");
- this.name=providerNode.getAttribute("name");
- this.configFile=oConfigFile;
- //bugbug: These calls should use nodefromid
- //var templatePath=this.configFile.selectSingleNode("/root/datafile[@id='" + this.datasetName + "']").getAttribute("template_path");
- //this.outputPath=this.configFile.selectSingleNode("/root/datafile[@id='" + this.datasetName + "']").getAttribute("output_path");
- //bugbug what if you cannot open the template- log the failure and end
- this.template=destination //getConfig(templatePath);
-
- this.qualifyingQueries= new Array();
- var qualifyNodes=providerNode.selectNodes("./qualify");
- for (var i=0;i<qualifyNodes.length;i++){
- this.qualifyingQueries[i]=qualifyNodes.item(i).getAttribute("value");
- //WScript.Echo(this.qualifyingQueries[i]);
- }
-
- this.groups= new Array();
- var groupNodes=providerNode.selectNodes("./group_by")
- for (var i=0;i<groupNodes.length;i++)
- {
- var g = groupNodes.item(i);
- var nameCaption=g.getAttribute("namecaption")
- var pnCaption=g.getAttribute("pncaption")
- var gid = g.getAttribute("id");
- var devlang = g.getAttribute("devlang");
-
- // peterril: added capability to force unique entries
- // duplicates are possible in situations like a page is for both VB and Script
- // where they are both objects and they may match multiple criteria.
- //
- // @unique can exist on a group or provider.
- var unique = (g.getAttribute("unique") ||
- g.selectSingleNode("..").getAttribute("unique")
- ? true : false);
-
- if (!nameCaption) nameCaption="";
- if (!pnCaption) pnCaption="";
- if (!devlang) devlang="";
-
- this.groups[i]=new GroupClass(groupNodes.item(i).getAttribute("id"),
- groupNodes.item(i).getAttribute("name"),
- groupNodes.item(i).getAttribute("value"),
- nameCaption, pnCaption, devlang);
- this.groups[i].unique = unique;
- }
-
- this.customPolls = new Array();
- var customPollNodes = providerNode.selectNodes("./dyndesc");
- for( var i=0; i<customPollNodes.length; i++ ){
- this.customPolls[i] = new Object();
- //this.customPolls[i].name = customPollNodes.item(i).getAttribute("name");
- this.customPolls[i].value = customPollNodes.item(i).getAttribute("value");
- }
-
- this.queryID=ensureAttribute(providerNode,"query_id");
- this.fixedID=ensureAttribute(providerNode,"fixed_id");
- //WScript.Echo(this.queryID);
- //WScript.Echo(this.fixedID);
- this.process=process;
- this.qualifies=qualifies;
- //this.save=save;
- this.updateDataFromDoc=updateDataFromDoc;
- this.getGroupName=getGroupName;
- this.getGroup=getGroup;
- this.ensureObject=ensureObject;
- return this;
- }
-
- function getDestination(destinationName)
- {
- for (var i=0;i<this.destinations.length;i++)
- {
- if (this.destinations[i].name==destinationName)
- {
- return this.destinations[i].template
- }
- }
- //bugbug: What about failure?
- }
-
- //Constructor for the destination class
- function DestinationClass(destinationNode)
- {
- var start = new Date(); //Used for perf testing
- this.startTime=start.getHours() + ":" + start.getMinutes() + ":" + start.getSeconds() + ":" + start.getMilliseconds()
- this.name=destinationNode.getAttribute("id");
- this.outputPath=destinationNode.getAttribute("output_path");
- this.template=getConfig(EnsureDriveLetter(destinationNode.getAttribute("template_path")));
- this.outputPath=EnsureDriveLetter(this.outputPath);
- return this
- }
-
- function EnsureDriveLetter(sPath)
- {
- if (sPath.substr(1,1)!=":")
- {
- return gScriptPath + sPath;
- }
- else
- {
- return sPath;
- }
- }
-
- function SaveAll()
- {
- var fso = new ActiveXObject("Scripting.FileSystemObject");
-
- var end = new Date();
- var sDate= end.getHours() + ":" + end.getMinutes() + ":" + end.getSeconds() + ":" + end.getMilliseconds()
- for (var i=0;i<this.destinationNodes.length;i++)
- {
- this.destinations[i].template.documentElement.setAttribute("StartTime",this.destinations[i].startTime);
- this.destinations[i].template.documentElement.setAttribute("EndTime",sDate);
-
- // make sure the file is not read-only.
- if (fso.FileExists(this.destinations[i].outputPath))
- fso.GetFile(this.destinations[i].outputPath).Attributes = 0;
-
- this.destinations[i].template.save(this.destinations[i].outputPath);
- }
- }
-
- function passAround(sPath)
- {
- WScript.Echo(sPath);
-
- var xmlDoc=getConfig(sPath);
- if( xmlDoc.parseError != 0 ){
- WScript.Echo( ".... ERROR: Unable to validate ('" + xmlDoc.parseError.reason + "')" );
- errorCount++;
- return;
- }
-
- for (var i=0;i<this.providerNodes.length;i++)
- {
- this.datasets[i].process(xmlDoc);
- }
- }
-
- function recursWalk(sPath){ //recursively walk the tree and process each xml file
- var colFiles=this.fs.GetFolder(sPath).files
- var enumFiles=new Enumerator(colFiles)
- for (;!enumFiles.atEnd(); enumFiles.moveNext())
- {
- var oFile=enumFiles.item();
- if (oFile.path.toLowerCase().indexOf(".xml") != -1)
- {
- //update(oFile.path);
- this.passAround(oFile.path);
- this.fileCount++;
- }
- }
- var colFolders=this.fs.GetFolder(sPath).SubFolders
- if (colFolders)
- {
- var enumFolders=new Enumerator(colFolders)
- for (;!enumFolders.atEnd(); enumFolders.moveNext())
- {
- var oFolder=enumFolders.item();
- this.walk(oFolder.path);
- }
- }
- }
-
- //process is a member of the DataSetClass
- function process(xmlDoc)
- {
- //Does the document qualify?
- if (this.qualifies(xmlDoc))
- {
- //get the data and insert it into the output file
- this.updateDataFromDoc(xmlDoc)
- }
- }
-
- function qualifies(xmlDoc)
- {
- sResult=true;
- for (var i=0;i<this.qualifyingQueries.length;i++)
- {
- if(this.qualifyingQueries[i]){
- try{
- var testNode=xmlDoc.selectSingleNode(this.qualifyingQueries[i]);
- if (!testNode)
- {
- //WScript.Echo(xmlDoc.url + " fails " + this.qualifyingQueries[i] + " of " + this.name);
- sResult=false;
- return sResult;
- }
- } catch(e) {
- WScript.Echo( ".... ERROR: Unable to qualify provider '" + this.name + "' ('" + e.message + "')" );
- errorCount++;
- this.qualifyingQueries[i] = null;
- sResult = false;
- }
- }
- }
- return sResult;
- }
-
-
- function save()
- {
- var end = new Date();
- var sDate= end.getHours() + ":" + end.getMinutes() + ":" + end.getSeconds() + ":" + end.getMilliseconds()
- this.template.documentElement.setAttribute("StartTime",this.startTime);
- this.template.documentElement.setAttribute("EndTime",sDate);
-
- // make sure the file is not read-only.
- if (fso.FileExists(this.outputPath))
- fso.GetFile(this.outputPath).Attributes = 0;
-
- this.template.save(this.outputPath);
- }
-
- function ensureAttribute(oNode,sAttribute)
- {
- var sResult=oNode.getAttribute(sAttribute);
- if (sResult)
- {
- return sResult;
- }
- else
- {
- return "";
- }
- }
-
- function GroupClass(sID, sName, sQuery, sNameCaption, sPNCaption, devlang)
- {
- this.id=sID;
- this.name=sName;
- this.query=sQuery;
- this.nameCaption=sNameCaption;
- this.pnCaption=sPNCaption;
- this.devlang=devlang;
- return this;
- }
-
- //returns the XMLdocument that is the configuration file
- function getConfig(sConfigPath)
- {
- var oConfigFile = new ActiveXObject("Microsoft.XMLDOM");
- oConfigFile.resolveExternals=true;
- oConfigFile.validateOnParse=true;
- oConfigFile.async=false;
- oConfigFile.load(sConfigPath);
- var parseErr=oConfigFile.parseError;
- if (parseErr.errorCode != 0)
- {
- var reason=parseErr.reason
- var line=parseErr.line
- var srcText=parseErr.srcText
- //WScript.Echo(reason + " " + line + " " + srcText);
- }
- return oConfigFile;
- }
-
- function updateDataFromDoc(sourceDoc)
- {
- //Gather up the key pieces of this member to be inserted into all it's parent objects and interfaces
- var sRid=sourceDoc.selectSingleNode("/inetsdk:topic/metadata/@id").value;
-
- if(sRid != this.fixedID && sRid != this.queryID){
- var oPN=sourceDoc.selectSingleNode("/inetsdk:topic/metadata/@pn");
- var oOverloaded=sourceDoc.selectSingleNode("/inetsdk:topic/metadata/@overloaded");
- var oProdRid = sourceDoc.selectSingleNode("/inetsdk:topic/content/info/product/@rid");
- var oMinver = sourceDoc.selectSingleNode("/inetsdk:topic/content/info/product/@minver");
- var sSortKey = sourceDoc.selectSingleNode("/inetsdk:topic/metadata/@name").value;
-
- if(oPN)
- var sPN=oPN.value;
-
- if (oOverloaded)
- var oParams = sourceDoc.selectNodes("/inetsdk:topic/content/params");
-
- if (oProdRid)
- var sProdRid = oProdRid.value;
-
- if (oMinver)
- var sMinver = oMinver.value;
-
- // peterril (11/1/01): This is added because of a request from GDI+.
- var tmp = sourceDoc.selectSingleNode("/inetsdk:topic/metadata/data[@name $eq$ 'sort']");
- if(tmp)
- sSortKey = tmp.getAttribute("value");
-
- //bugbug: member element needs to be a child of member type element
- var sType=sourceDoc.selectSingleNode("/inetsdk:topic/metadata/@type").value
-
- // peterril: special case happens when a page is only an attribute.
- var sName = "";
- if( sType != "attribute" )
- sName=sourceDoc.selectSingleNode("/inetsdk:topic/metadata/@name").value
-
- // Use alternative name where available (currently only for script command ids)
- var sAltName = "";
- var oName = sourceDoc.selectSingleNode("/inetsdk:topic/metadata/devlang[@value='scr']/@name");
- if ( oName )
- sAltName = oName.value;
-
- var oDesc = pollCustom( this.customPolls, sourceDoc);
- if( !oDesc )
- oDesc=sourceDoc.selectSingleNode("/inetsdk:topic/content/desc"); // try to get main description.
- if( !oDesc ){
- oDesc=sourceDoc.selectSingleNode("/inetsdk:topic//abstract"); // common in overviews.
-
- // -peterril-
- // the only way I know to rename a node is to create a new one and transfer the information.
- //
- // the reason that I rename the node is because I wanted to maintain consistancy with the
- // objectmembers code. This way, the objectmembers code can always assume a desc.
- //
- if( oDesc ){
- var t = oDesc;
- oDesc = sourceDoc.createElement("desc");
- var t = t.firstChild;
- while(t){
- oDesc.appendChild( t.cloneNode(true) );
- t = t.nextSibling;
- }
- }
- }
- if( !oDesc )
- oDesc = sourceDoc.createElement("desc"); // create blank description.
-
-
- var bNotSupported = (sourceDoc.selectSingleNode("/inetsdk:topic/metadata/@not_supp") ? true : false);
- var bNotImplemented = (sourceDoc.selectSingleNode("/inetsdk:topic/metadata/@not_impl") ? true : false);
-
- if( bNotSupported )
- oDesc.text = "Not currently supported.";
- else if( bNotImplemented )
- oDesc.text = "Not currently implemented.";
-
- var oDescClone;
-
- if (this.fixedID!="")
- {
- var group=this.getGroup(sourceDoc);
- if (!group) return;
-
- var objectNode=this.ensureObject(this.fixedID,group);
- if ( group.devlang != "" )
- objectNode.setAttribute( "devlang", group.devlang );
-
- var member=this.template.createElement("member")
- member.setAttribute("rid",sRid);
- if(sName) member.setAttribute("name",sName);
- if ( sAltName != "" ) member.setAttribute( "altname", sAltName );
- member.setAttribute("sortkey", sSortKey);
- if (oPN) member.setAttribute("pn", sPN);
- if (oProdRid) member.setAttribute("prodrid", sProdRid);
- if (oMinver) member.setAttribute("minver", sMinver);
-
- var oDispID = sourceDoc.selectSingleNode("/inetsdk:topic/metadata/applies/iface[@rid = '" + parentID + "']/@dispid");
- if( oDispID ) var sDispID = oDispID.value;
-
- if(oDispID) member.setAttribute("dispid", sDispID);
-
- member.setAttribute("type",sType);
- objectNode.appendChild(member);
-
- if (oDesc){
- if( oDesc[0] ){
- for( var j=0; j<oDesc.length; j++ ){
- oDescClone = oDesc[j].cloneNode(true);
- member.appendChild(oDescClone);
- }
- } else {
- oDescClone=oDesc.cloneNode(true);
- member.appendChild(oDescClone); //Add this member to the object
-
- if( !oDesc.firstChild ){ // echo warning that there is no description.
- WScript.Echo(".... WARNING: A default description was created because none existed in document.");
- warningCount++;
- }
- }
- } else {
- WScript.Echo( ".... ERROR: Unable to retrieve required description." );
- errorCount++;
- }
-
- if (oOverloaded)
- {
- for (i = 0; i < oParams.length; i++)
- member.appendChild(oParams[i].cloneNode(true));
- }
- }
- else //BUGBUG: Missing dispid from the ifaces and autoiid on the members.
- {
- var group=this.getGroup(sourceDoc);
- if (!group) return;
-
- var parentNodes=sourceDoc.selectNodes(this.queryID);
- for (var i=0;i<parentNodes.length;i++)
- {
- var parentID=parentNodes[i].text
- var oAIs = parentNodes[i].selectNodes("../accessinfo"); // hack to go back up to parent tag.
- var oAIClone = null;
- var objectNode=this.ensureObject(parentID, group, group.devlang);
-
- //peterril: check to verify that there are no duplicates if set in config.
- var isUnique = true;
- if( group.unique ) isUnique = isUniqueRecord( sRid, objectNode );
-
- if( !isUnique )
- {
- WScript.Echo(".... ERROR: Discarded record because uniquness was enforced [" + parentID + "].");
- errorCount++;
- }
- else
- {
- if ( group.devlang != "" )
- objectNode.setAttribute( "devlang", group.devlang );
-
- var member = this.template.createElement("member");
- member.setAttribute("rid",sRid);
- if(sName) member.setAttribute("name",sName);
- if ( sAltName != "" ) member.setAttribute( "altname", sAltName );
- member.setAttribute("sortkey", sSortKey);
- if(oPN) member.setAttribute("pn",sPN);
- if(oMinver) member.setAttribute("minver",sMinver);
-
- var oDispID = sourceDoc.selectSingleNode("/inetsdk:topic/metadata/applies/iface[@rid = '" + parentID + "']/@dispid");
- if( oDispID ) var sDispID = oDispID.value;
-
- if(oDispID) member.setAttribute("dispid", sDispID);
- member.setAttribute("type",sType);
- objectNode.appendChild(member);
-
- // insert description information.
- if (oDesc){
- if( oDesc[0] ){
- for( var j=0; j<oDesc.length; j++ ){
- oDescClone = oDesc[j].cloneNode(true);
- member.appendChild(oDescClone);
- }
- } else {
- oDescClone=oDesc.cloneNode(true);
- member.appendChild(oDescClone); //Add this member to the object
-
- if( !oDesc.firstChild ){ // echo warning that there is no description.
- WScript.Echo(".... WARNING: A default description was created because none existed in document.");
- warningCount++;
- }
- }
- } else {
- WScript.Echo( ".... ERROR: Unable to retrieve required description." );
- errorCount++;
- }
-
- // insert accessinfo information.
- for( var j=0; j<oAIs.length; j++ ){
- var oAI = oAIs[j];
- oAIClone = oAI.cloneNode( true );
- member.appendChild( oAIClone );
- }
-
- if (oOverloaded)
- {
- for (i = 0; i < oParams.length; i++)
- member.appendChild(oParams[i].cloneNode(true));
- }
- }
- }
- }
- }
- }
-
- function isUniqueRecord(idToFind, sourceData){
- var result = true;
-
- if(idToFind && sourceData){
- var t = sourceData.selectSingleNode("member[@rid='" + idToFind + "']");
- if(t) result = false;
- }
-
- return result;
- }
-
- function pollCustom( aPollsFound, sourceDoc ){
- for( var i=0; i<aPollsFound.length; i++ ){
- var searchValue = aPollsFound[i].value;
-
- var foundNodes = sourceDoc.selectNodes( searchValue );
-
- if( foundNodes.length >= 1 )
- return renameNode(foundNodes[i], "desc");
- else
- return null;
- }
- }
-
- function renameNode( srcNode, newName ){
- var xml = new ActiveXObject("Microsoft.XMLDOM");
-
- if( srcNode && newName ){
- if( srcNode.nodeName == newName )
- return srcNode.cloneNode(true);
-
- var t = xml.createElement(newName);
- var c = srcNode.firstChild;
- while(c){
- t.appendChild(c.cloneNode(true));
- c = c.nextSibling;
- }
-
- for( var i=0; i<srcNode.attributes.length; i++ ){
- var att = srcNode.attributes[i];
- t.setAttribute( att.nodeName, att.nodeValue );
- }
-
- return t;
- } else
- return null;
- }
-
- function ensureObject(sParentID, oType, devlang){
- //var objectNode=this.template.selectSingleNode("/objectmembers/parent[@id='" + sParentID + "']")
- var objectNode=this.template.nodeFromID(sParentID)
- if (!objectNode)
- {
- objectNode=this.template.createElement("parent")
- this.template.documentElement.appendChild(objectNode)
- objectNode.setAttribute("id",sParentID);
- }
-
- var typeNode = "";
- if(devlang)
- typeNode=this.template.selectSingleNode("/objectmembers/parent[@id='" + sParentID + "']/type[@gid='" + oType.id + "' $and$ @devlang='" + devlang + "']")
- else
- typeNode=this.template.selectSingleNode("/objectmembers/parent[@id='" + sParentID + "']/type[@gid='" + oType.id + "']")
- if (!typeNode)
- {
- typeNode=this.template.createElement("type")
- objectNode.appendChild(typeNode)
- typeNode.setAttribute("value",oType.name);
- typeNode.setAttribute("namecaption",oType.nameCaption);
- typeNode.setAttribute("gid", oType.id);
- typeNode.setAttribute("pncaption",oType.pnCaption);
- if(devlang) typeNode.setAttribute("devlang", devlang);
- }
- return typeNode;
- }
-
- function getGroupName(xmlDoc)
- {
- var sResult="unknown";
- for (var i=0;i<this.groups.length;i++)
- {
- if (xmlDoc.selectSingleNode(this.groups[i].query))
- {
- sResult=this.groups[i].name;
- break;
- }
- }
- return sResult;
- }
-
- function getGroup(xmlDoc)
- {
- for (var i=0;i<this.groups.length;i++)
- {
- if(this.groups[i].query){
- try{
- if (xmlDoc.selectSingleNode(this.groups[i].query))
- {
- return this.groups[i];
- }
- } catch(e) {
- WScript.Echo( ".... ERROR: Unable to qualify provider '" + this.name + "' ('" + e.message + "')" );
- errorCount++;
- this.groups[i].query = null;
- return null;
- }
- }
- }
- }
-
-